﻿<body>
<style>
.westtable-span1 .westtable-span2 {
	font-family: Courier, "Courier New", monospace;
	font-size: 12px;
}
.westtable-span1 {
	color: #000000;
	font-weight: bold;
}

</style>	
<div id="dlg-ydbf" class="easyui-dialog" title="约定拜访" style="width:750px;height:500px;" data-options="buttons:'#dlg-ydbf-btn',resizable:false,modal:true,closable: false,cache:false">
	<div class="easyui-layout" style="width:100%;height:100%;padding:0px;">
		<div region="north" style="border:none;height:150px;background:#dbeaf9;overflow:hidden">
			<table border="0" width="717px" style="margin:10px"> 		
				<tr> 
					<td width="15%" class="westtable-span1">拜访日期：</td> 
					<td width="35%" class="westtable-span2">
						<input disabled id="ydFeedbackDate" class="easyui-validatebox" readonly type="text" style="width:195px;"></input> 
					</td> 
					<td width="15%" class="westtable-span1">拜访客户：</td> 
					<td width="35%" class="westtable-span2"> 
						<input id="ydCustree" class="easyui-combotree" value="--请选择--" data-options="onBeforeExpand:function(node){getChildren(node);},animate:true,required:true" style="width:200px;">		
					</td> 		
				</tr> 
				<tr>
					<td class="westtable-span1">上/下午</td> 
					<td class="westtable-span2"> 
						<select id="ydDayType" class="easyui-combobox" data-options="panelHeight:'auto'" style="width:200px;">
							<option selected value="am">上午</option>
							<option value="pm">下午</option>
							<option value="all">全天</option>
						</select>
					</td>
					<td class="westtable-span1">&nbsp;</td>
					<td> 
						<div id="div-isinplan" style="font-weight:normal;">计划内&nbsp;&nbsp;<input type="radio" onclick="getUnplanCustomers(2);" name="ydRadio" checked>&nbsp;&nbsp;计划外&nbsp;&nbsp;<input type="radio" onclick="getUnplanCustomers(1);" name="ydRadio"></div>
					</td> 
				</tr> 		
				<tr> 
					<td class="westtable-span1">类型：</td> 
					<td class="westtable-span2"> 
						<select disabled id="ydType" class="easyui-combobox" style="width:200px;" data-options="panelHeight:'auto'">
							<option>约见</option>
						</select> 
					</td>
					<td class="westtable-span1">拜访程序</td>
					<td> 
						<select disabled id="ydVisitProcess" class="easyui-combobox" style="width:200px;" data-options="valueField:'id',textField:'text',panelHeight:'auto',required:true">
						</select>
					</td> 
				</tr>
				<tr> 	
					<td class="westtable-span1">开始时间：</td>
					<td class="westtable-span2"> 				
						<input id="ydStratTime" class="easyui-timespinner" data-options="required:true" value="12:00" style="width:200px;"> 			
					</td>		
					<td class="westtable-span1">结束时间：</td> 			
					<td class="westtable-span2"> 				
						<input id="ydEndTime" class="easyui-timespinner" data-options="required:true" value="12:00" style="width:200px;"> 			
					</td> 			 		
				</tr> 	
				<tr> 
					<td class="westtable-span1">上级主管</td>
					<td> 
						<select id="ydParentEmp" class="easyui-combobox" data-options="valueField:'id',textField:'text',panelHeight:'auto'" style="width:200px;"> 
							<option>--请选择--</option> 
						</select> 
					</td> 
				</tr>
			</table>
		</div>
		<div region="center" style="padding:0px;overflow:auto">
			<div id="tab-ydfb" class="easyui-tabs" data-options="fit:true,tools:'#tab-ydfb-tools',border:false"></div>			
			<div id="tab-ydfb-tools">
				<a href="#" id="tab-tools-add" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-add'" onclick="javascript:expandYdItemDlg('add');"></a>
				<a href="#" id="tab-tools-remove" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-remove'" onclick="javascript:removeCheckedItems();"></a>
				<!--<a href="#" id="tab-tools-icm" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-tip'" onclick="javascript:addDocuments();"></a>
				-->
				<a href="#" class="easyui-linkbutton" data-options="plain:true,iconCls:'icon-refresh'" onclick="javascript:refreshflag=true;showYdfbTabContent();"></a>
			</div>
		</div>
	</div>
</div>  

<div id="dlg-ydbf-btn" style="background:#dbeaf9;">
	<a href="#" id="saveVisitBaseBtn" class="easyui-linkbutton" onclick="javascript:saveYdFeedback();">&nbsp;&nbsp;保存&nbsp;&nbsp;</a>
	<a href="#" class="easyui-linkbutton" onclick="javascript:$('#dlg-ydbf').dialog('destroy');$('#tab-ydfb').dialog('destroy')">&nbsp;&nbsp;关闭&nbsp;&nbsp;</a>
</div>

<script>
	/**
		动态添加拜访客户节点
	*/
	oval_node_str = '';
	function getChildren(node){
		oval_node = node;
		var oval_node_ids = oval_node.id.split('f');
		if(oval_node_str.indexOf(oval_node.id)!=-1)return;
		var paramsstr = "{'gradeflag':'"+oval_node_ids[1]+"','employeeid':"+oval_user_search+",'customerid':'"+oval_node_ids[0]+"'}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'getvisitcustomers',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getChildrenCallback);
	}
	
	function getChildrenCallback(data){
		if(data.successflag=="true"){	
			if(data.result.customers != undefined){
				var t = $('#ydCustree').combotree('tree');
				t.tree('append', {
					parent: oval_node.target,
					data: data.result.customers
				});
				oval_node_str += oval_node.id;
				t.tree('collapse',oval_node.target);
				t.tree('expand',oval_node.target);				
			}
		}	
	}
	
	/**
		计划内与计划外拜访客户的切换
	*/
	function getUnplanCustomers(num){
		var paramsstr = "{'cudate':'"+ovaldateStr+"','isplan':"+num+",'employeeid':"+oval_user_search+",'visitfeedbackid':"+visitfeedbackid+"}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_visitfeedback', 'getvisitfeedback',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getUnplanCustomersCallback);
	}
	
	function getUnplanCustomersCallback(data){
		if(data.successflag=="true"){
			if(data.result.customers == undefined)
				$('#ydCustree').combotree('setValue','--请选择--');	
			else{	
				$('#ydCustree').combotree('setValue','--请选择--');
				$('#ydCustree').combotree('loadData',data.result.customers);	
			}
		}
	}
	
	/**
		保存数据更改数据
	*/
	function saveYdFeedback(){
		var customer = $('#ydCustree').combotree('getValue');
		var processid = $('#ydVisitProcess').combobox('getValue');
		var parentempid = $('#ydParentEmp').combobox('getValue');
		var daytype = $('#ydDayType').combobox('getValue');
		var starttime = $('#ydStratTime').timespinner('getValue');
		var endtime = $('#ydEndTime').timespinner('getValue');
		var targetid = null;
		var targettype = null;
		var orgid = null;
		if(customer=="--请选择--"){
			$.messager.alert('提示','请选择一个拜访客户！','info');
			return;
		}else{
			if(customer.split('f').length!=1){
				var targetid = customer.split('f')[0];
				var targettype = customer.split('f')[1];
				var orgid = customer.split('f')[2];
				if(targettype=='113' || targettype=='114'){
					targettype='1';
					orgid = customer.split('f')[0];
				}
			}
		}
		if(processid=="--请选择--"){
			$.messager.alert('提示','请选择一个拜访程序！','info');
			return;
		}
		if(ydbasedata==undefined)
			var basedetails = "[]";
		else{
			if(currentTab=='基本反馈')add2BaseDetail();
			var basedetails = JSON.stringify(ydbasedata.result.itemdetails).replace(/"/g, "'");
			basedetails = basedetails.replace(/null/g, "''");
			basedetails = basedetails.replace(/''''/g, "''");
		}
		if(ydskudata==undefined)
			var skudetails = "[]";
		else{
			var skudetails = JSON.stringify(ydskudata.result.itemdetails).replace(/"/g, "'");
			skudetails = skudetails.replace(/null/g, "''");
			skudetails = skudetails.replace(/''''/g, "''");
		}
		if(ydimcdata==undefined)
			var imcdetails = "[]";
		else{
			var imcdetails = JSON.stringify(ydimcdata.result.allitems).replace(/"/g, "'");
			imcdetails = imcdetails.replace(/null/g, "''");
			imcdetails = imcdetails.replace(/''''/g, "''");
		}	
		var paramsstr = "{'orgid':'"+orgid+"','feedbackdate':'"+ovaldateStr+"','starttime':'"+starttime+"','endtime':'"+endtime+"','operate':'save','employeeid':"+oval_user_search+",'targetid':"+targetid+",'targettype':"+targettype+",'processid':'"+processid+"','parentemployeeid':'"+parentempid+"','daytype':'"+daytype+"','visitfeedbackid':"+visitfeedbackid+",'ydbasedata':"+basedetails+",'ydskudata':"+skudetails+",'ydimcdata':"+imcdetails+",'checkedskuids':'"+checkedskuids.join()+"','checkedimcids':'"+checkedimcids.join()+"'}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_ydfeedback', 'saveydfeedback',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, saveYdFeedbackSuccess);
	}
	
	function saveYdFeedbackSuccess(data){
		if(data.successflag=="true"){
			$('#dlg-ydbf').dialog('destroy');	
			$('#tab-ydfb').dialog('destroy')			
			$.messager.show({
				title:'提示',
				msg: '数据保存成功！',
				timeout:3000,
				showType:'slide'
			});
			refresh();
		}
	}	
	
	/**
		从服务器获取初始数据
	*/
	getYdFeedbackInfo();
	
	function getYdFeedbackInfo(){
		ydbasedata = undefined;
		ydskudata = undefined;
		ydimcdata = undefined;
		currentTab = undefined;
		refreshflag = true;
		checkedskuids =  new Array();
		checkedimcids =  new Array();
		storage = window.localStorage;
		itemId = null;
		itemDetailTitle = null;
		var paramsstr = "{'cudate':'"+ovaldateStr+"','employeeid':"+oval_user_search;
		if(visitfeedbackid!=null && visitfeedbackid!=""){
			paramsstr += ",'visitfeedbackid':"+visitfeedbackid;
		}
		paramsstr += "}";
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_ydfeedback', 'getydfeedback',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getYdFeedbackInfoReturn);
	}
	
	function getYdFeedbackInfoReturn(data){
		if(data.successflag=="true"){			
			$('#ydFeedbackDate').val(ovaldateStr);	
			$('#ydParentEmp').combobox('loadData',data.result.parentempsel);
			$('#ydParentEmp').combobox('setValue',data.result.parentempsel[0].id);	
			$('#ydCustree').combotree('loadData',data.result.customers);		
			$('#ydVisitProcess').combobox('loadData',data.result.processsel);	
			$('#ydVisitProcess').combobox('setValue',data.result.processsel[0].id);					
			if(data.result.feedbackinfo != undefined){				
				$(':radio').attr("disabled",true);		
				$('#ydFeedbackDate').val(ovaldateStr);
				$('#ydDayType').combobox('setValue',data.result.feedbackinfo.daytype);
				$('#ydDayType').combobox('disable');
				$('#ydVisitProcess').combobox('setValue',data.result.feedbackinfo.processid);
				$('#ydVisitProcess').combobox('disable');
				$('#ydStratTime').timespinner('setValue',data.result.feedbackinfo.starttimestr);
				$('#ydStratTime').timespinner('disable');
				$('#ydEndTime').timespinner('setValue',data.result.feedbackinfo.endtimestr);
				$('#ydEndTime').timespinner('disable');
				$('#ydParentEmp').combobox('setValue',data.result.feedbackinfo.mainvisituserid);
				$('#ydParentEmp').combobox('disable');
				if(data.result.targetinfo != undefined){
					$('#ydCustree').combotree('setValue',data.result.targetinfo.text);
					$('#ydCustree').combotree('disable');
				}else{
					$('#ydCustree').combotree('setValue',data.result.feedbackinfo.targetid+'f113f1');
					$('#ydCustree').combotree('disable');
				}
			}
			if(data.result.dictionary != undefined)dictionary = data.result.dictionary;
			if(data.result.typeinfo != undefined){
				$('#tab-ydfb').tabs({   
					onSelect: function(title,index){  
						if(currentTab=='基本反馈'){
							add2BaseDetail();
							var basedetails = JSON.stringify(ydbasedata.result.itemdetails).replace(/"/g, "'");
						}
						currentTab = title; 			
						$('#tab-tools-add').linkbutton('enable');
						$('#tab-tools-remove').linkbutton('enable');		
						$('#tab-tools-icm').linkbutton('enable');		
						if(title=="基本反馈"){
							$('#tab-tools-add').linkbutton('disable');
							$('#tab-tools-remove').linkbutton('disable');
							$('#tab-tools-icm').linkbutton('disable');
						}
						if(title=="拜访资料"){
							$('#tab-tools-add').linkbutton('disable');
							$('#tab-tools-icm').linkbutton('disable');
						}
						showYdfbTabContent();		
					}   
				});  
				
				if(data.result.typeinfo.base>0){
					addTab("base","基本反馈",true);
				}
				if(data.result.typeinfo.sku>0){
					addTab("sku","拜访产品",false);
				}else{
					addTab("sku","拜访产品",true);				
				}
				//addTab("imc","拜访资料",false);
			}
		}
	}
	
	/**
		根据条件显示tab内数据
	*/
	function showYdfbTabContent(){
		ydflag = 'tab';
		if(currentTab == '基本反馈'){
			itemtype = "base";
			if(ydbasedata!=undefined && !refreshflag){
				getItemDetailCallback(ydbasedata);
				return;
			}
		}else{
			if(currentTab == '拜访产品'){
				itemtype = "sku";
				fieldCode = "prodcode";
				fieldText = "prodname";
				fieldValue = "prodid";		
				var _tab = $('#tab-ydfb').tabs('getTab',currentTab); 
				$('#tab-ydfb').tabs('update',{
					tab: _tab,	
					options: {
						content: '<table id="tb-grid-'+itemtype+'"></table>'
					}
				});		
				$('#tb-grid-'+itemtype).datagrid({
					height:249,
					nowrap: false,
					border: false,
					autoRowHeight: false,
					striped: true,
					singleSelect:false,
					fitColumns:true,
					checkOnSelect: false,
					selectOnCheck: false,
					columns:[[
						{field: fieldValue,checkbox: true},
						{field: fieldCode,title:currentTab.substr(2,2)+"代码",width:208},
						{field: fieldText,title:currentTab.substr(2,2)+"名称",width:402},
						{field: 'orgid',title:'操作',width:80,align:'center',
							formatter:function(value,row,index){	
								
								var str = '<a href="#" id="editFeedbackBtn" class="easyui-linkbutton" data-options="iconCls:"icon-edit"" onclick="javascript:expandYdItemDlg(\'view\',['+eval('row.'+fieldValue)+',\''+eval('row.'+fieldText)+'\']);">编辑</a>';
								return str;
							}
						}
					]]
				});
			}else{
				itemtype = "imc";
				fieldCode = "documentcode";
				fieldName = "documentname";
				fieldText = "documentdesc";
				fieldValue = "visitdocumentid";
				var _tab = $('#tab-ydfb').tabs('getTab',currentTab); 
				$('#tab-ydfb').tabs('update',{
					tab: _tab,	
					options: {
						content: '<table id="tb-grid-'+itemtype+'"></table>'
					}
				});
				$('#tb-grid-'+itemtype).datagrid({
					height:249,
					nowrap: false,
					border: false,
					autoRowHeight: false,
					striped: true,
					singleSelect:false,
					fitColumns:true,
					checkOnSelect: false,
					selectOnCheck: false,
					columns:[[
						{field: fieldValue,checkbox: true},
						{field: fieldCode,title:currentTab.substr(2,2)+"代码",width:150},
						{field: fieldName,title:currentTab.substr(2,2)+"名称",width:150},
						{field: fieldText,title:currentTab.substr(2,2)+"描述",width:310},
						{field: 'documenturl',title:'操作',width:80,align:'center',
							formatter:function(value,row,index){										
								var str = '<a href="'+value+'" id="editFeedbackBtn" class="easyui-linkbutton">下载</a>';
								return str;
							}
						}
					]]
				});
			}
			if(!refreshflag){
				switch(currentTab){
					case '拜访产品':
						if(ydskudata!=undefined){
							getItemDetailCallback(ydskudata);
							return;
						}							
						break;
					case '拜访资料':
						if(ydimcdata!=undefined){
							getItemDetailCallback(ydimcdata);
							return;
						}							
						break;
				}
			}
		}
		getItemDetail();
	}	
	
	/**
		获取初始明细数据
	*/
	function getItemDetail(){
		operateModel = "";
		var paramsstr = "{'employeeid':"+oval_user_search+",'itemtype':'"+itemtype+"'";
		if(visitfeedbackid!=null && visitfeedbackid!=""){
			paramsstr += ",'visitfeedbackid':"+visitfeedbackid;
		}
		paramsstr += "}"
		var variable = new Array('__methodName', '__token', 'pagename', 'actionname','__params');
		var value = new Array('wsActionJSON', token, 'p_ydfeedback', 'getydfeedbackdetails',paramsstr);
		var dataStr = getJsonData(variable, value);
		connectionServlet(dataStr, getItemDetailCallback);
	}
	
	function getItemDetailCallback(data){
		refreshflag = false;
		if(data.successflag=="true"){	
			var strHTML = '';
			if(itemtype == 'base'){
				ydbasedata = data;
			}else if(itemtype == 'sku'){
				ydskudata = data;
			}else if(itemtype == 'imc'){
				ydimcdata = data;
			}			
			itemDetails = data.result.itemdetails;
			var allItems = data.result.allitems;			
			if(allItems != undefined && ydflag == 'tab'){
				$('#tb-grid-'+itemtype).datagrid('loadData',{                                                                     
					"rows": allItems                                                          
				});
			}
			if(ydflag == 'tab' && itemtype != 'base')return;
			if(itemtype == 'sku' && operateModel == 'add'){
				itemDetails = data.result.demodetails;
			}
			if(itemDetails != undefined){				
				for(i=0;i<itemDetails.length;i++){
					if(operateModel=='view' && itemDetails[i].prodid!=itemId)continue;
					var type = itemDetails[i].feedbacktype;
					var id = itemDetails[i].visitprocessactionid;
					var dictype = itemDetails[i].sourcetype;
					var value;
					switch(type){
						case 1:
							value = itemDetails[i].feedbacknumber;
							break;
						case 2:
							value = itemDetails[i].feedbacktext;
							break;
						case 3:
							value = itemDetails[i].feedbackcheck;
							break;
						case 4:
							value = itemDetails[i].feedbackselect;
							break;
						case 5:
							value = itemDetails[i].feedbackattrachid;
							break;
						case 6:
							value = itemDetails[i].feedbackmultiselect;
							break;
						case 8:
							value = itemDetails[i].feedbackselect;
							break;
					}
					strHTML += '<div style="padding:5px;border-bottom: 1px solid #99BBE8;">';		
					strHTML += '<p class="westtable-span1"><span style="width:90px;float:left">'+itemDetails[i].actionname+'：</span>';	
					strHTML += '&nbsp;&nbsp;&nbsp;&nbsp;'+createFormEle(type,id,value,dictype,itemId)+'</p>';					
					strHTML += '</div>';			
				}
			}		
			if(ydflag == 'tab'){
				var _tab = $('#tab-ydfb').tabs('getTab',currentTab); 
					$('#tab-ydfb').tabs('update',{
						tab: _tab,	
						options: {
							content: strHTML
					}
				});			
			}else{
				if(itemtype == 'sku'){
					var isdisabled = "";
					if(itemId!=null){
						isdisabled = "disabled";
					}
					newHTML = '<div style="padding:5px;border-bottom: 1px solid #99BBE8;"><p class="westtable-span1"><span style="width:90px;float:left">产品：</span>&nbsp;&nbsp;&nbsp;&nbsp;<select style="width:400px;" '+isdisabled+' data-options="onSelect: function(r){setSkuSelectOption(r);},panelHeight:\'300\'" class="easyui-combobox" id="'+itemtype+'001"><option value="null">--请选择--</option>';
					var product = JSON.parse(storage["oval_product"]);
					var newYdItems = JSON.stringify(ydskudata.result.allitems); 
					for (p=0;p<product.length;p++){
							if(operateModel!="view" && newYdItems.indexOf(product[p].prodid)!=-1)continue;
							var flag = "";
							if(product[p].prodid==1){
								flag = "selected";
							}
							newHTML += '<option '+ flag +' value="'+ product[p].prodid +'">'+ product[p].prodname +'</option>';
					}						
					newHTML += '</select></p></div>';
					$('#dlg-yditem').dialog({   
						title: currentTab, 
						content: newHTML+strHTML
					}); 
					$('#dlg-yditem').dialog('open');	
					if(operateModel=='view'){
						$('#'+itemtype+'001').combobox('setValue',itemId)
					}			
				}
			}
		}
	}
	
	/**
		根据选择产品设置dictionary选择项
	*/
	function setSkuSelectOption(record){
		var prodid = record.value;
		for(i=0;i<itemDetails.length;i++){
			var type = itemDetails[i].feedbacktype;
			if(type==4){
				var id = itemDetails[i].visitprocessactionid;
				var dictype = itemDetails[i].sourcetype;
				var strJson = '[{"text":"--请选择--","value":"","selected":true}';
				var dictionary = JSON.parse(storage["oval_dictionary"]);
				var flag = false;
				for (p=0;p<dictionary.length;p++){	
					if(dictionary[p].type==dictype && dictionary[p].relatedprodid!=null)flag = true;							
					if(dictionary[p].type==dictype && (dictionary[p].relatedprodid+"").indexOf(prodid)!=-1){
						strJson += ',{"value":"'+ dictionary[p].value +'","text":"'+ dictionary[p].valuename +'"}';
					}
				}	
				strJson += ']';	
				if(flag)$('#sku'+id).combobox('loadData',JSON.parse(strJson));	
			}
		}
	}
	
	/**
		保存基本反馈
	*/
	function add2BaseDetail(){
		var newitemDetails = ydbasedata.result.itemdetails;
		for(i=0;i<newitemDetails.length;i++){
			var type = newitemDetails[i].feedbacktype;
			var id = newitemDetails[i].visitprocessactionid;
			var dictype = newitemDetails[i].sourcetype;
			switch(type){
				case 1:
					value = $('#'+itemtype+id).val();
					if(value=="")value="null";
					newitemDetails[i].feedbacknumber=value;
					break;
				case 2:
					value = $('#'+itemtype+id).val();
					if(value=="")value=null;
					newitemDetails[i].feedbacktext=value;
					break;
				case 3:
					if($('#'+itemtype+id).attr("checked")=="checked")
						value = 'N';
					else
						value = 'Y';
					newitemDetails[i].feedbackcheck=value;
					break;
				case 4:
					value = $('#'+itemtype+id).combobox('getValue');	
					if(value=='null')value=null;
					newitemDetails[i].feedbackselect=value;
					break;
				case 5:
					value = $('#'+itemtype+id).val();
					if(value=="")value = "null";
					newitemDetails[i].feedbackattrachid='null';
					break;
				case 6:
					value = "";
					var multiObj = $("[name='"+itemtype+id+"']").each(function(){
						if(this.checked){
							value += this.value +',';
						}
					}); 
					if(value!=""){
						value = value.substring(0,value.length-1);
					}
					newitemDetails[i].feedbackmultiselect=value;
					break;
				case 8:
					value = $('#'+itemtype+id).combobox('getValue');
					if(value=="")value="null";
					newitemDetails[i].feedbackselect='null';
					break;
			}
		}
	}
	
	
	/**
		保存拜访产品，拜访资料反馈数据
	*/
	function add2ItemDetail(){
		var newitemDetails = JSON.parse(JSON.stringify(ydskudata.result.demodetails));		
		if(operateModel=='view')
			newitemDetails = ydskudata.result.itemdetails;
		var prodivalue = $('#'+itemtype+'001').combobox('getValue');
		if(prodivalue=="null"){
			$.messager.alert('提示','请选择一个产品！','info');
			return;
		}
		for(i=0;i<newitemDetails.length;i++){
			if(operateModel=='view' && newitemDetails[i].prodid!=itemId)continue;
			var type = newitemDetails[i].feedbacktype;
			var id = newitemDetails[i].visitprocessactionid;
			var dictype = newitemDetails[i].sourcetype;
			newitemDetails[i].prodid = prodivalue;
			switch(type){
				case 1:
					value = $('#'+itemtype+id).val();
					if(value=="")value="null";
					newitemDetails[i].feedbacknumber=value;
					break;
				case 2:
					value = $('#'+itemtype+id).val();
					newitemDetails[i].feedbacktext=value;
					break;
				case 3:
					if($('#'+itemtype+id).attr("checked")=="checked")
						value = 'N';
					else
						value = 'Y';
					newitemDetails[i].feedbackcheck=value;
					break;
				case 4:
					value = $('#'+itemtype+id).combobox('getValue');
					if(value=="")value="null";
					newitemDetails[i].feedbackselect=value;
					break;
				case 5:
					value = $('#'+itemtype+id).val();
					if(value=="")value = "null";
					newitemDetails[i].feedbackattrachid='null';
					break;
				case 6:
					value = "";
					var multiObj = $("[name='"+itemtype+id+"']").each(function(){
						if(this.checked){
							value += this.value +',';
						}
					}); 
					if(value!=""){
						value = value.substring(0,value.length-1);
					}
					newitemDetails[i].feedbackmultiselect=value;
					break;
				case 8:
					value = $('#'+itemtype+id).combobox('getValue');
					if(value=="")value="null";
					newitemDetails[i].feedbackselect='null';
					break;
			}
		}
		if(operateModel=='view'){
			$('#dlg-yditem').dialog('destroy');
			return;
		}
		var product = JSON.parse(storage["oval_product"]);
		for (p=0;p<product.length;p++){
			if(product[p].prodid==$('#'+itemtype+'001').combobox('getValue')){		
				ydskudata.result.allitems = ydskudata.result.allitems.concat({'prodid':product[p].prodid,'prodname':product[p].prodname,'prodcode':product[p].prodcode});
				ydskudata.result.itemdetails = ydskudata.result.itemdetails.concat(newitemDetails);
				break;
			}
		}
		$('#dlg-yditem').dialog('destroy');
		showYdfbTabContent();
	}	
	
	/**
		移除所选产品，资料项目
	*/
	function removeCheckedItems(){
		var checkedItemArray = $('#tb-grid-'+itemtype).datagrid('getChecked');	
		if(checkedItemArray.length==0)return;
		$.messager.confirm('警告','确定移除所选项吗?', function(r){
			if (r){
				execRemoveItems(checkedItemArray);
			}
		});	
	}
	
	function execRemoveItems(arr){
		if(currentTab=="拜访产品")
			var checkedids = checkedskuids;
		else
			var checkedids = checkedimcids;
		for(i=0;i<arr.length;i++){
			$.merge(checkedids, [arr[i].prodid])
		}	
		var allItems = ydskudata.result.allitems;
		var itemDetails = ydskudata.result.itemdetails;
		var newAllItems = new Array();
		var newItemDetails = new Array();
		for(i=0;i<allItems.length;i++){
			var prodid = allItems[i].prodid.toString();
			if(checkedids.join().indexOf(prodid)!=-1)continue;
			$.merge(newAllItems, [allItems[i]])			
		}
		for(i=0;i<itemDetails.length;i++){
			var prodid = itemDetails[i].prodid.toString();
			if(prodid.indexOf(checkedids.join())!=-1)continue;
			$.merge(newItemDetails, [itemDetails[i]])			
		}
		ydskudata.result.allitems = newAllItems;
		ydskudata.result.itemdetails = newItemDetails;
		if(currentTab=="拜访产品")
			checkedskuids = checkedids;
		else
			checkedimcids = checkedids;
		showYdfbTabContent();
	}	
	
	/**
		设置级联相关dictionary指南
	*/
	function chg4RelatedType(dictype,actionid,dicvalue){
		for(j=0;j<itemDetails.length;j++){
			if(itemDetails[j].relatedactionid==actionid){
				var vid = eval("itemDetails[j].visit"+itemtype+"feedbackid");
			}
		}
		var dictionary = JSON.parse(storage["oval_dictionary"]);
		for(k=0;k<dictionary.length;k++){
			if(dictionary[k].type==dictype){
				if(dictionary[k].value==dicvalue){
					dictype = dictionary[k].relatedtype;
					break;
				}
			}
		}	
		var newdic = [{"valuename":"--请选择--","value":"null","selected":true}];
		for (p=0;p<dictionary.length;p++){
			if(dictionary[p].type==dictype){
				newdic = newdic.concat(dictionary[p]);
			}
		}	
		$('#'+itemtype+vid).combobox({   
			url:'combobox_data.json',   
			valueField:'value',   
			textField:'valuename'  
		}); 
		$('#'+itemtype+vid).combobox('loadData',newdic);	
	}
	
	/**
		创建指南反馈项
	*/	
	function createFormEle(type,id,value,dictype,prodid){
		var elementStr;
		if(value==undefined)value="";
		if(type==1){						
			elementStr = '<input style="width:390px;" class="easyui-numberbox" onchange="editFlag=1" id="'+ itemtype + id +'" value="'+ value +'"/>';	
			return elementStr;
		}else if(type==2){							
			elementStr = '<textarea style="width:390px;height:50px" onchange="editFlag=1" id="'+ itemtype + id +'">'+ value +'</textarea>';
			return elementStr;						
		}else if(type==3){
			var flag = '';
			if(value=='Y')flag = 'checked';
			elementStr = '<input id="'+ itemtype + id +'" '+ flag +' onchange="editFlag=1" type="checkbox"/><label style="padding-right:10px;">是/否</label>';	
			return elementStr;	
		}else if(type==4){
			elementStr = '<select style="width:400px;" data-options="onSelect: function(rec){editFlag=1;chg4RelatedType(\''+ dictype +'\','+ id +',rec.value)},panelHeight:\'auto\'" class="easyui-combobox" id="'+ itemtype + id +'"><option value="null">--请选择--</option>';
			var dictionary = JSON.parse(storage["oval_dictionary"]);
			for (p=0;p<dictionary.length;p++){
				if(dictionary[p].type==dictype){
					if(dictionary[p].relatedprodid!=null && prodid==null && itemtype=='sku')break;
					var flag = "";
					if(dictionary[p].value==value){
						flag = "selected";
					}
					if(itemtype=='sku'){
						if(dictionary[p].relatedprodid!=null && (dictionary[p].relatedprodid+"").indexOf(prodid)!=-1)
							elementStr += '<option '+ flag +' value="'+ dictionary[p].value +'">'+ dictionary[p].valuename +'</option>';
						if(dictionary[p].relatedprodid==null)
							elementStr += '<option '+ flag +' value="'+ dictionary[p].value +'">'+ dictionary[p].valuename +'</option>';
						
					}else{
						elementStr += '<option '+ flag +' value="'+ dictionary[p].value +'">'+ dictionary[p].valuename +'</option>';
					}
				}
			}
			elementStr += '</select>';
			return elementStr;	
		}else if(type==5){
			elementStr = '上传';	
			return elementStr;	
		}else if(type==6){
			elementStr = '';	
			valueArray = value.split(",");
			var dictionary = JSON.parse(storage["oval_dictionary"]);
			for (p=0;p<dictionary.length;p++){
				if(dictionary[p].type==dictype){
					for (q=0;q<valueArray.length;q++){
						if(dictionary[p].value == valueArray[q])break;
					}
					var flag = "";
					if(q < valueArray.length){
						flag = "checked";
					}
					elementStr += '<input name="'+ itemtype + id +'" '+ flag +' onchange="editflag=1" type="checkbox" value="'+ dictionary[p].value +'"/><label style="padding-right:10px;">'+ dictionary[p].valuename +'</label>';	
				}
			}							
			return elementStr;	
		}else if(type==8){
			elementStr = '<select style="width:400px;" data-options="panelHeight:\'auto\'" class="easyui-combobox" id="'+ itemtype + id +'" " onchange="editFlag=1;"><option value="null">--请选择--</option>';
			var dicvalue;
			if(value!=''){
				var dictionary = JSON.parse(storage["oval_dictionary"]);
				for(j=0;j<itemDetails.length;j++){
					if(itemDetails[j].visitprocessactionid==id){
						dicvalue = itemDetails[j].feedbackselect;
						dictype = itemDetails[j].sourcetype;
					}
				}
				for(k=0;k<dictionary.length;k++){
					if(dictionary[k].type==dictype){
						if(dictionary[k].value==dicvalue){
							dictype = dictionary[k].relatedtype;
							break;
						}
					}
				}				
				for (p=0;p<dictionary.length;p++){
					if(dictionary[p].type==dictype){
						var flag = "";
						if(dictionary[p].value==value){
							flag = "selected";
						}
						elementStr += '<option '+ flag +' value="'+ dictionary[p].value +'">'+ dictionary[p].valuename +'</option>';
					}
				}	
			}				
			elementStr += '</select>';
			return elementStr;	
		}
	}	
		
	/**
		增加显示tab面板
	*/
	function addTab(_id,_title,_selected){
		if($('#tab-ydfb').tabs('getTab',_title)==null){
			$('#tab-ydfb').tabs('add',{
				id: _id,
				title: _title,
				selected: _selected
			});	
		}
	}	
	
	/**
		添加产品反馈明细
	*/
	function expandYdItemDlg(flag,array){
		operateModel = flag;
		if(operateModel=='add'){
			var customer = $('#ydCustree').combotree('getValue');
			if(customer=="--请选择--" || customer==""){
				$.messager.alert('提示','请先选择一个拜访客户！','info');
				return;
			}
			var textStr='&nbsp;&nbsp;添加&nbsp;&nbsp;';
			}
		else 
			var textStr='&nbsp;&nbsp;修改&nbsp;&nbsp;';
		if(array!=undefined){
			itemId = array[0];
			itemDetailTitle = array[1];
		}else{
			itemId = null;
			itemDetailTitle = null;		
		}
		$('#createContainer').html('<div id="dlg-yditem"></div>');
		ydflag='dlg';
		if(currentTab=="拜访产品"){
			$('#dlg-yditem').dialog({   			
				title: '拜访产品', 
				width: 550,   
				height: 450, 
				modal: true , 
				closed: true,
				buttons: [{
					text: textStr,
					handler:function(){
						add2ItemDetail();
					}
				},{
					text:'&nbsp;&nbsp;取消&nbsp;&nbsp;',
					handler:function(){
						$('#dlg-yditem').dialog('destroy');
					}
				}]
			}); 
			getItemDetailCallback(ydskudata);
		}
		$('.dialog-button').css({'background':'#dbeaf9'});
	}
	
	/**
		添加资料反馈明细
	*/
	function showAddDocumentDlg(){
		$('#createContainer').html('<div id="dlg-yditem"></div>');
		var userid = localStorage.getItem("oval_userid");	
		var allItems = ydskudata.result.allitems;
		var prodids = '[-1';
		for(i=0;i<allItems.length;i++){
			var prodid = allItems[i].prodid.toString();
			prodids += ','+prodid;
		}
		prodids += ']';
		$('#dlg-yditem').dialog({
			title: '拜访资料', 
			width: 767,   
			height: 573,
			modal: true , 
			content: '<iframe scrolling="auto" frameborder="0" src="http://docserver:8899/_layouts/15/OVAL.SFE.SharepointProject/documentcenterPicker.aspx?k='+token+'&userid='+userid+'&prodids='+prodids+'&functionname=addDocuments" style="width:750px;height:500px"></iframe>',
			buttons: [{
				text: '&nbsp;&nbsp;添加&nbsp;&nbsp;',
				handler:function(){
					add2ItemDetail();
				}
			},{
				text:'&nbsp;&nbsp;取消&nbsp;&nbsp;',
				handler:function(){
					$('#dlg-yditem').dialog('destroy');
				}
			}]
		}); 
		$('.dialog-button').css({'background':'#dbeaf9'});
	}
	function addDocuments(documents){
		ydimcdata.result.itemdetails = ydimcdata.result.itemdetails.concat(documents);
		$('#tt').tabs('select','拜访资料');
	}
</script>
</body>